﻿using Appliaction.Dto.FG;
using Appliaction.IAppServices.FG;
using AutoMapper;
using Domain.Entitys.FG;
using Domain.IRepositorys.FG;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Appliaction.AppServices.FG
{
    public class FG_Finished_Goods_StoreService : IFG_Finished_Goods_StoreService
    {
        private readonly IFG_Finished_Goods_StoreRepository fG_Finished_Goods_StoreRepository;
        private readonly IMapper mapper;

        public FG_Finished_Goods_StoreService(IFG_Finished_Goods_StoreRepository fG_Finished_Goods_StoreRepository,IMapper mapper)
        {
            this.fG_Finished_Goods_StoreRepository = fG_Finished_Goods_StoreRepository;
            this.mapper = mapper;
        }

        /// <summary>
        /// 添加成品入库信息及其明细
        /// </summary>
        /// <param name="finishedGoodsStoreDetailsAddDto"></param>
        /// <returns></returns>
        public async Task<int> FG_Finished_Goods_StoreAddAsync(FinishedGoodsStoreDetailsAddDto finishedGoodsStoreDetailsAddDto)
        {
            FG_Finished_Goods_Store fG_Finished_Goods_Store = mapper.Map<FG_Finished_Goods_Store>(finishedGoodsStoreDetailsAddDto.FG_Finished_Goods_StoreAddDto);
            List<FG_Finished_Goods_Store_Details> fG_Finished_Goods_Store_Details = mapper.Map<List<FG_Finished_Goods_Store_Details>>(finishedGoodsStoreDetailsAddDto.FG_Finished_Goods_Store_DetailsAddDtos);
            return await fG_Finished_Goods_StoreRepository.FG_Finished_Goods_StoreAddAsync(fG_Finished_Goods_Store,fG_Finished_Goods_Store_Details);
        }

        /// <summary>
        /// 逻辑删除产品入库信息
        /// </summary>
        /// <param name="fG_Finished_Goods_StoreDelDto"></param>
        /// <returns></returns>
        public async Task<int> FG_Finished_Goods_StoreDelAsync(FG_Finished_Goods_StoreDelDto fG_Finished_Goods_StoreDelDto)
        {
            FG_Finished_Goods_Store fG_Finished_Goods_Store = mapper.Map<FG_Finished_Goods_Store>(fG_Finished_Goods_StoreDelDto);
            return await fG_Finished_Goods_StoreRepository.FG_Finished_Goods_StoreDelAsync(fG_Finished_Goods_Store);
        }

        /// <summary>
        /// 修改成品入库信息及其明细
        /// </summary>
        /// <param name="finishedGoodsStoreDetailsUpdateDto"></param>
        /// <returns></returns>
        public async Task<int> FG_Finished_Goods_StoreUpdateAsync(FinishedGoodsStoreDetailsUpdateDto finishedGoodsStoreDetailsUpdateDto)
        {
            FG_Finished_Goods_Store fG_Finished_Goods_Store = mapper.Map<FG_Finished_Goods_Store>(finishedGoodsStoreDetailsUpdateDto.FG_Finished_Goods_StoreUpdateDto);
            return await fG_Finished_Goods_StoreRepository.FG_Finished_Goods_StoreUpdateAsync(fG_Finished_Goods_Store,finishedGoodsStoreDetailsUpdateDto.FG_Finished_Goods_Store_Details);
        }

        /// <summary>
        /// 修改成品入库审核状态，减少库存预计出库数量，增加库存数量
        /// </summary>
        /// <param name="fG_Finished_Goods_StoreUpdateAuditDto"></param>
        /// <returns></returns>
        public async Task<int> FG_Finished_Goods_StoreUpdateAuditAsync(FG_Finished_Goods_StoreUpdateAuditDto fG_Finished_Goods_StoreUpdateAuditDto)
        {
            FG_Finished_Goods_Store fG_Finished_Goods_Store = mapper.Map<FG_Finished_Goods_Store>(fG_Finished_Goods_StoreUpdateAuditDto);
            return await fG_Finished_Goods_StoreRepository.FG_Finished_Goods_StoreUpdateAuditAsync(fG_Finished_Goods_Store);
        }

        /// <summary>
        /// 根据成品入库编号查询成品入库信息
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<FG_Finished_Goods_Store> GetFG_Finished_Goods_StoreByCodeAsync(string code)
        {
            return await fG_Finished_Goods_StoreRepository.GetFG_Finished_Goods_StoreByCodeAsync(code);
        }

        /// <summary>
        /// 条件查询成品入库总数
        /// </summary>
        /// <param name="Warehouse_Code"></param>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<int> Get_Finished_Goods_StoreCountAsync(string Warehouse_Code, string code, char auditStutas)
        {
            return await fG_Finished_Goods_StoreRepository.Get_Finished_Goods_StoreCountAsync(Warehouse_Code, code,auditStutas);
        }

        /// <summary>
        /// 根据成品入库编号查询成品入库明细
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public async Task<List<FG_Finished_Goods_Store_Details>> Get_Finished_Goods_Store_DetailsByCodeAsync(string code)
        {
            return await fG_Finished_Goods_StoreRepository.Get_Finished_Goods_Store_DetailsByCodeAsync(code);
        }

        /// <summary>
        /// 分页条件查询成品入库信息
        /// </summary>
        /// <param name="Warehouse_Code"></param>
        /// <param name="code"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public List<FG_Finished_Goods_Store_Info> Get_Finished_Goods_Store_Infos(string Warehouse_Code, string code, int currentPage, int pageSize, char auditStatus)
        {
            return fG_Finished_Goods_StoreRepository.Get_Finished_Goods_Store_Infos(Warehouse_Code, code, currentPage, pageSize,auditStatus);
        }
    }
}
